rgPlot <- function(outcomeMatrix, dims, file="X") {
	if (file == "X") {X11()}
	else png(filename=file)
	nOutcomes <- prod(dims)
	m <- array(1:nOutcomes, dim=dims)
	layout(m)
	layout.show(nOutcomes)
	
	for (j in 1:prod(dims)) {
		thisOutcome <- matrix(data=as.integer(outcomeMatrix==j), nrow=dim(outcomeMatrix)[1], ncol=dim(outcomeMatrix)[2])
		thisOutcomeMean <- apply(thisOutcome, MARGIN=1,FUN=mean)
		hist(thisOutcomeMean,10, col="blue", main=paste("Outcome: ", j, sep=""), xlab=paste("Mean Proportion = ", mean(thisOutcomeMean), sep=""), ylab="",xlim=c(0, 1))
		}
	

	if (file == "X") {} 
	else dev.off()
	
	}
	
rgPlotWithPayoffs <- function(outcomeMatrix, dims, payoffs, filename="X") {
	if (filename == "X") {X11()}
	else pdf(file=filename)
	nOutcomes <- prod(dims)
	m <- array(1:nOutcomes, dim=dims)
	layout(m)
	#layout.show(nOutcomes)
	
	for (j in 1:prod(dims)) {
		thisOutcome <- matrix(data=as.integer(outcomeMatrix==j), nrow=dim(outcomeMatrix)[1], ncol=dim(outcomeMatrix)[2])
		thisOutcomeMean <- apply(thisOutcome, MARGIN=1,FUN=mean)
		histTitle1 <- switch(j, "(C,C)", "(D,C)", "(C,D)", "(D,D)")
		histTitle2 <- paste(payoffs[j,], collapse=",")
		
		histTitle <- paste(histTitle1, ": (", histTitle2, ")", sep="")
		hist(thisOutcomeMean,10, col="blue", main=histTitle, xlab=paste("Mean Proportion = ", mean(thisOutcomeMean), sep=""), ylab="",xlim=c(0, 1))
		}
	

	if (filename == "X") {} 
	else dev.off()
}

rgPlotWithStates <- function(outcomeMatrix, dims, filename="X") {
	if (filename == "X") {X11()}
	else pdf(file=filename)
	nOutcomes <- prod(dims)
	m <- array(1:nOutcomes, dim=dims)
	layout(m)
	#layout.show(nOutcomes)
	
	for (j in 1:prod(dims)) {
		thisOutcome <- matrix(data=as.integer(outcomeMatrix==j), nrow=dim(outcomeMatrix)[1], ncol=dim(outcomeMatrix)[2])
		thisOutcomeMean <- apply(thisOutcome, MARGIN=1,FUN=mean)
		histTitle <- switch(j, "(C,C)", "(D,C)", "(C,D)", "(D,D)")
		
		hist(thisOutcomeMean,(0:20)/20, col="blue", main=histTitle, xlab=paste("Mean Proportion = ", mean(thisOutcomeMean), sep=""), ylab="",xlim=c(0, 1))
		}
	

	if (filename == "X") {} 
	else dev.off()
}

rgPlotPublicGoods <- function(coopMatrix, dims, file="X") {
	if (file == "X") {X11()}
	else png(filename=file)
	nPlayers <- prod(dims)
	m <- array(1:nPlayers, dim=dims)
	layout(m)
	layout.show(nPlayers)
	
	for (j in 1:nPlayers) {
	
		histTitle <- paste("Player ", j, sep="")
		hist(coopMatrix[,j],10, col="blue", main=histTitle, xlab=paste("Mean Proportion = ", mean(coopMatrix[,j]), sep=""), ylab="",xlim=c(0, 1))
		}
	

	if (file == "X") {} 
	else dev.off()

}



	
	
